#!/bin/bash
#centos76 init  + docker-ce ntp 
yum update -y
yum install wget -y
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
yum install telnet net-tools ntp epel-release container-selinux -y
systemctl enable ntpd
systemctl start ntpd
ntpdate cn.pool.ntp.org
sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2
sudo yum-config-manager \
  --add-repo \
  http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum -y install docker-ce-18.09.0 docker-ce-cli-18.09.0
sudo systemctl enable docker.service
mkdir -p /data/docker/data-root
mkdir -p /etc/docker

cat > /etc/docker/daemon.json <<EOF
{
  "data-root": "/data/docker/data-root",
  "registry-mirrors" : [
    "https://6zy5kcio.mirror.aliyuncs.com"
  ]
}
EOF
systemctl enable docker && systemctl restart docker
if ! docker-compose -h >/dev/null 2>&1;then
    echo "===  请安装 docker-compose"
    cd /usr/local/bin
    wget https://zwfile.yonyougov.top/share/crux-tools/docker-compose --no-check-certificate
    chmod +x docker-compose
else
  echo "docker-compose 已经安装"
fi
systemctl restart firewalld
firewall-cmd \
  --add-port=22/tcp \
  --add-port=80/tcp \
  --add-port=443/tcp \
  --add-port=2379/tcp \
  --add-port=2380/tcp \
  --add-port=8472/udp \
  --add-port=9099/tcp \
  --add-port=9796/tcp \
  --add-port=10250/tcp \
  --add-port=10254/tcp \
  --add-port=6443/tcp \
  --add-port=30000-50000/tcp \
  --add-port=30000-50000/udp \
  --add-port=500-4500/udp \
  --permanent
firewall-cmd --reload
cat > /etc/sysctl.d/k8s.conf << EOF
net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
vm.swappiness=0
vm.max_map_count=655360 
EOF

sysctl -p /etc/sysctl.d/k8s.conf